package com.labor.code.zgscapp.utils;


import android.app.Activity;
import android.os.Process;

import java.util.ArrayList;
import java.util.List;

/**
 * Activity 工具类
 *
 */
public class ActivityUtils {
    private List<Activity>  activityList = new ArrayList<>();
    private static ActivityUtils instance;

    public static synchronized ActivityUtils getInstance(){
        if (instance == null){
            instance = new ActivityUtils();
        }
        return  instance;
    }

    /**
     * 添加activity 到容器中
     * @param activity
     */
    public void addActivity(Activity activity){
        if (activityList == null){
            activityList = new ArrayList<>();
        }
        activityList.add(activity);
    }

    /**
     * 移除activity
     */
    public void removeActivity(Activity activity){
        if (activityList != null){
            activityList.remove(activity);
        }
    }

    /**
     * 关闭全部activity
     */
    public void exitSystem(){
        for (Activity activity : activityList){
            if (activity != null){
                activity.finish();
            }
        }
        Process.killProcess(Process.myPid());
        System.exit(0);
    }

}
